import React, { createRef } from "react";
import Child from "./Child";
type Ipt = React.RefObject<HTMLInputElement> | null
class RefCom extends React.Component<any, any>{
    // 创建ref引用
    ipt:Ipt = createRef<HTMLInputElement>()
    // ipt:Ipt
    // constructor(props:any){
    //     super(props)
    //     this.ipt=createRef<HTMLInputElement>()
    // }
    Child:any=React.createRef<Child>()
    handleClick=()=>{
        console.log(this.ipt!.current!.value)
        this.ipt?.current?.focus()
    }
    render(): React.ReactNode {
        return (
            <fieldset>
                <legend>Ref</legend>
                <input type="text" ref={this.ipt} />
                <Child ref={this.Child}/>
                <button onClick={this.handleClick}>点击</button>
            </fieldset>
        )
    }
}

export default RefCom